#include "QuerySpecification.h"
#include "GpuParser.h"
#include "Utilities.h"

QuerySpecification::QuerySpecification(){
	appType = "";
	searchPhase = "";
	invertedListPath = "";
	invertedIndexLengthFile = "";
	searchMethod = "";
	numOfDocToExpand = NUMBER_NOT_SPECIFIED;
	totalDimension = NUMBER_NOT_SPECIFIED;
	topK =  NUMBER_NOT_SPECIFIED;
}

void QuerySpecification::update(std::string xmlSpecFile){
	GpuParser parser(xmlSpecFile);	
	std::string readInString;	

	readInString = parser.getAppType();
	if (!readInString.empty()){
		appType = readInString;
	}

	readInString = parser.getSearchPhase();
	if (!readInString.empty()){
		searchPhase = readInString;
	}

	readInString = parser.getInvertedListPath();
	if (!readInString.empty()){
		invertedListPath = readInString;
	}

	readInString = parser.getInvertedIndexLengthFile();
	if (!readInString.empty()){
		invertedIndexLengthFile = readInString;
	}

	readInString = parser.getSearchMethod();
	if (!readInString.empty()){
		searchMethod = readInString;
	}

	int readInInt = parser.getNumOfDocToExpand();
	if (readInInt != NUMBER_NOT_SPECIFIED){
		numOfDocToExpand = readInInt;
	}

	readInInt = parser.getTotalDimension();
	if (readInInt != NUMBER_NOT_SPECIFIED){
		totalDimension = readInInt;
	}

	readInInt = parser.getTopK();
	if (readInInt != NUMBER_NOT_SPECIFIED){
		topK = readInInt;
	}

	std::vector<int> readInIntVec = parser.getMinDomainForAllDimension();
	if (!readInIntVec.empty()){
		minDomainForAllDimension = readInIntVec;
	}

	readInIntVec = parser.getMaxDomainForAllDimension();
	if (!readInIntVec.empty()){
		maxDomainForAllDimension = readInIntVec;
	}

	parser.getQuerySet(querySet);

}
